package org.vectrics.recruiter.struts.admin;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.vectrics.provider.CoreServiceLocator;

/**
 * @author pgoette
 * Clase encargada de buscar todos las personas. 
 *
 */

public class UserSearchAction extends PersonSearchAction {
	transient static Logger log = Logger.getLogger(UserSearchAction.class);


	/**
	 * @see PersonSearchAction#isChangePage(HttpServletRequest, UserSearchForm)
	 */
	@Override
	protected boolean isChangePage(HttpServletRequest request,
			UserSearchForm form) {
		boolean resultado = super.isChangePage(request, form);
	    if (resultado) {
			if (this.getCriteria().isNotEmployees()) {
				form.setPersonType("candidate");
			}
			if (this.getCriteria().getEmployeesOnly()) {
				form.setPersonType("employ");
			}	
	    }
	    return resultado;
	}
	
	/**
	 * @see PersonSearchAction#SetearCriterio(UserSearchForm, HttpServletRequest)
	 */
	@Override
	protected void SetearCriterio(UserSearchForm form,
			HttpServletRequest request) {
		// Creo el criterio.
		this.setCriteria(CoreServiceLocator.createPersonSearchCriteria());
		
		super.SetearCriterio(form, request);
		
		// Si la persona es un empleado seteo setEmployeesOnly en true, si es candidate notEmployees en true
		if ((form.getPersonType()!=null)&&(!form.getPersonType().trim().equals(""))){
			if (form.getPersonType().trim().equalsIgnoreCase("employ")){
				this.getCriteria().setEmployeesOnly(true);					
			} else {
				if (form.getPersonType().trim().equalsIgnoreCase("candidate")){
					this.getCriteria().setNotEmployees(true);
				}
			}
		}
		HttpSession session = request.getSession();
		session.setAttribute("userSelectCriteria", this.getCriteria());
		
	}
	
	
}
